home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscGaugePalette / MiscGaugeViewInspector.m < prev    next >
Encoding:
Text File  |  1995-04-14  |  6.5 KB  |  246 lines

  1. /****************************************************************************
  2.   CLASS:                MiscGaugeViewInspector
  3.   
  4.   See the interface file for more information on this class.
  5.  ****************************************************************************/
  6.  
  7. #import <appkit/appkit.h>
  8. #import "MiscGaugeView.subproj/MiscGaugeView.h"
  9. #import "MiscGaugeViewInspector.h"
  10.  
  11.  
  12. @implementation MiscGaugeViewInspector
  13.  
  14. - init
  15. {
  16.     char buf[MAXPATHLEN+1];
  17.     id bundle;
  18.     
  19.     [super init];
  20.     
  21.     // Load the inspector's nib file.
  22.     bundle = [NXBundle bundleForClass:[MiscGaugeView class]];
  23.     [bundle getPath: buf forResource: "MiscGaugeViewInspector" ofType:"nib"];
  24.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  25.     return self;
  26. }
  27.  
  28.     
  29. - attribChanged:sender
  30. {
  31.     // One of the attributes changed, so find out which one and update us.
  32.     // Syncronize the slider with it's matching form cell. The sender is
  33.     // the attribForm. After we set the attrib. we check back with the
  34.     // object and see what the value was really set to (since it may have
  35.     // been illegal) and update the form cell.
  36.     int selIndex = [sender selectedRow];
  37.     
  38.     switch (selIndex)
  39.     {
  40.         case 0:    // Start angle changed.
  41.             [object setStartAngle: [sender floatValueAt: 0] ];
  42.             [sender setFloatValue: [object startAngle] at: 0];
  43.             break;
  44.             
  45.         case 1:    // Angle range changed.
  46.             [object setAngleRange: [sender floatValueAt: 1] ];
  47.             [sender setFloatValue: [object angleRange] at: 1];
  48.             break;
  49.             
  50.         case 2: // Hand ratio changed.
  51.             [object setHandRatio: [sender floatValueAt: 2] ];
  52.             [sender setFloatValue: [object handRatio] at: 2];
  53.             break;
  54.  
  55.         case 3:    // Tick ratio changed.
  56.             [object setTickRatio: [sender floatValueAt: 3] ];
  57.             [sender setFloatValue: [object tickRatio] at: 3];
  58.             break;
  59.  
  60.         case 4: // Tick interval changed.
  61.             [object setTickInterval: [sender intValueAt: 4] ];
  62.             [sender setFloatValue: [object tickInterval] at: 4];
  63.             break;
  64.      }        
  65.     
  66.     // Tick interval has no slider so don't send a message.
  67.     if (selIndex != 4)
  68.         [ [sliderMatrix cellAt: selIndex : 0] 
  69.                         setFloatValue: [sender floatValueAt: selIndex] ];
  70.  
  71.     return [super ok: sender];
  72. }
  73.  
  74.  
  75. - sliderChanged: sender
  76. {
  77.     // A slider changed, so update the inspected object and 
  78.     // the attribForm. The sender is the sliderMatrix.
  79.     Cell *selectedCell = [sender selectedCell];
  80.     
  81.     switch ([sender selectedTag])
  82.     {
  83.         case 0:    // Start angle changed.
  84.             [object setStartAngle: [selectedCell floatValue] ];
  85.             break;
  86.             
  87.         case 1:    // Angle range changed.
  88.             [object setAngleRange: [selectedCell floatValue] ];
  89.             break;
  90.             
  91.         case 2: // Hand ratio changed.
  92.             [object setHandRatio: [selectedCell floatValue] ];
  93.             break;
  94.  
  95.         case 3:    // Tick ratio changed.
  96.             [object setTickRatio: [selectedCell floatValue] ];
  97.             break;
  98.      }
  99.  
  100.     // Set the matching attribute in the form, so it and it's
  101.     // slider have the same value.
  102.     [attribsForm setFloatValue: [selectedCell floatValue] 
  103.                     at: [sender selectedTag] ];
  104.     return [super ok: sender];
  105. }
  106.  
  107.  
  108. - backgroundColorChanged:sender
  109. {
  110.     // The sender is a NXColorWell.
  111.     [object setBackgroundColor: [sender color] ];
  112.     return [super ok: sender];
  113. }
  114.  
  115.  
  116. - gaugeColorChanged:sender
  117. {
  118.     // The sender is a NXColorWell.
  119.     [object setGaugeColor: [sender color] ];
  120.     return [super ok: sender];
  121. }
  122.  
  123.  
  124. - textColorChanged:sender
  125. {
  126.     // The sender is the NXColorWell representing text color.
  127.     [object setTextColor: [sender color] ];
  128.     return [super ok: sender];
  129. }
  130.  
  131.  
  132. - valueChanged:sender
  133. {
  134.     // A value in the value form changed, so find out which one and
  135.     // update the object. The sender is the valueForm.
  136.     int selIndex = [sender selectedIndex];
  137.     
  138.     switch (selIndex)
  139.     {
  140.         case 0:    // Min value changed.
  141.             [(MiscGaugeView *)object setMinValue: [sender floatValueAt: 0] ];
  142.             // The max. value may have changed if it became less than the min.
  143.             [sender setFloatValue: [(MiscGaugeView *)object maxValue] at: 1];
  144.             break;
  145.         
  146.         case 1: // Max value changed.
  147.             [(MiscGaugeView *)object setMaxValue: [sender floatValueAt: 1] ];
  148.             // The min value may have changed if it became more than the max.
  149.             [sender setFloatValue: [(MiscGaugeView *)object minValue] at: 0];
  150.             break;
  151.             
  152.         case 2:    // Current value changed.
  153.             [object setFloatValue: [sender floatValueAt: 2] ];
  154.             break;
  155.      }
  156.      
  157.     // Since any of the above could have changed the value of the gauge 
  158.     // (or the new value wasn't acceptable..above or below the max and
  159.     // min), get the current value from the object itself and update the
  160.     // formcell.
  161.     [sender setFloatValue: [object floatValue] at: 2];
  162.  
  163.     return [super ok: sender];
  164. }
  165.  
  166.  
  167. - titleFieldChanged: sender
  168. {
  169.     [object setTitle: [sender stringValue] ];
  170.     return [super ok: sender];
  171. }
  172.  
  173.  
  174. - titlePositionChanged: sender
  175. {
  176.     switch ([sender selectedTag])
  177.     {
  178.         case 0:
  179.             [object setTitlePosition: NX_ATTOP];
  180.             break;
  181.         
  182.         case 1:
  183.             [object setTitlePosition: NX_ATBOTTOM];
  184.             break;
  185.      }
  186.     return [super ok: sender];
  187. }
  188.  
  189.  
  190. - revert: sender
  191. {
  192.     // The place to ask the inspected object for all it's values, so we
  193.     // can fill up the inspector's fields and color wells.
  194.  
  195. //    [backgroundColorWell setColor: [object backgroundColor] ];
  196.     [gaugeColorWell setColor: [object gaugeColor] ];
  197.     [textColorWell setColor: [object textColor] ];
  198.     [titleField setStringValue: [object title] ];
  199.     
  200.     [valueForm setFloatValue: [(MiscGaugeView *)object minValue] at: 0];
  201.     [valueForm setFloatValue: [(MiscGaugeView *)object maxValue] at: 1];
  202.     [valueForm setFloatValue: [object floatValue] at: 2];
  203.     
  204.     [attribsForm setFloatValue: [object startAngle] at: 0];
  205.     [attribsForm setFloatValue: [object angleRange] at: 1];
  206.     [attribsForm setFloatValue: [object handRatio] at: 2];
  207.     [attribsForm setFloatValue: [object tickRatio] at: 3];
  208.     [attribsForm setIntValue: [object tickInterval] at: 4];
  209.  
  210.     [ [sliderMatrix cellAt: 0 : 0] setFloatValue: [object startAngle] ];
  211.     [ [sliderMatrix cellAt: 1 : 0] setFloatValue: [object angleRange] ];
  212.     [ [sliderMatrix cellAt: 2 : 0] setFloatValue: [object handRatio] ];
  213.     [ [sliderMatrix cellAt: 3 : 0] setFloatValue: [object tickRatio] ];
  214.     
  215.     if ([object titlePosition] == NX_ATTOP)
  216.         [titlePositionMatrix selectCellAt: 0 : 0];
  217.     else
  218.         [titlePositionMatrix selectCellAt: 1 : 0];
  219.         
  220.     return [super revert: sender];
  221. }
  222.  
  223.  
  224. - (BOOL)wantsButtons
  225. {
  226.     return NO;
  227. }
  228.  
  229. @end
  230.  
  231.  
  232. @implementation MiscGaugeViewInspector (NibInitialization)
  233.  
  234. - awakeFromNib
  235. {
  236.     // Set all the decimal places for the attributes.
  237.     [[attribsForm cellAt: 0 : 0] setFloatingPointFormat: YES left: 3 right: 1];
  238.     [[attribsForm cellAt: 1 : 0] setFloatingPointFormat: YES left: 3 right: 1];
  239.     [[attribsForm cellAt: 2 : 0] setFloatingPointFormat: YES left: 1 right: 2];
  240.     [[attribsForm cellAt: 3 : 0] setFloatingPointFormat: YES left: 1 right: 2];
  241.     return self;
  242. }        
  243.  
  244. @end
  245.  
  246.